package com.mxt.biz.impl;

import com.mxt.biz.CustomerBiz;
import com.mxt.dao.CustomerDao;
import com.mxt.entity.Customer;
import com.mxt.entity.QueryCustomer;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class CustomerBizImpl implements CustomerBiz {
    @Resource
    private CustomerDao customerDao;
    public  boolean delete(int id){
        return  customerDao.delete(id);
    }
    public  boolean update(Customer customer){
        return  customerDao.update(customer);
    }
    public Customer queryByID(int id){
        return  customerDao.queryByID(id);
    }
    public List<Customer> queryAll(){
        return  customerDao.queryAll();
    }

    public  List<Customer> queryByQueryCustomer(QueryCustomer qc){
        int rows=qc.getRows();//每页显示几条记录
        int page=qc.getPage();//当前页
        int count=customerDao.queryByQueryCustomerCount(qc);//总条数
        if(count==0){
            return null;
        }
        int countPage=count%rows==0?(count/rows):(count/rows+1);//总页数
        page=page<1?1:page;
        page=page>countPage?countPage:page;

        qc.setPage(page);
        qc.setStart((page-1)*rows);
        qc.setPageCount(countPage);
        qc.setXia(page+1);
        qc.setShang(page-1);
        return  customerDao.queryByQueryCustomer(qc);
    }
    public  int queryByQueryCustomerCount(QueryCustomer qc){
        return  customerDao.queryByQueryCustomerCount(qc);
    }
}
